package com.project.erp.common.utils.upload;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.ProgressListener;

/**
 * 文件上传进度控制
 * @author zyj
 * 
 */
public class FileUploadListener implements ProgressListener {

	private HttpSession session;

	public FileUploadListener(HttpServletRequest request) {
		session = request.getSession();
		StateProgress stateProgress = new StateProgress();
		session.setAttribute("stateProgress", stateProgress);
	}

	@Override
	public void update(long pBytesRead, long pContentLength, int pItems) {
		//System.out.println("update:" + pBytesRead + ";" + pContentLength + ";" + (int)(((float)pBytesRead/(float)pContentLength)*100) + ";" + pItems);  
		StateProgress stateProgress = (StateProgress) session.getAttribute("stateProgress");  
		stateProgress.setReadedBytes(pBytesRead);
		stateProgress.setTotalBytes(pContentLength);
		stateProgress.setCurrentItem(pItems);
	}

}
